//
//  WPWalletDetailTableViewCell.m
//  ZhongChouPingTai
//
//  Created by WeiPan on 16/4/13.
//  Copyright © 2016年 WPJoe. All rights reserved.
//

#import "WPWalletDetailTableViewCell.h"

@interface WPWalletDetailTableViewCell ()
@property (nonatomic, strong) UILabel * titleLabel;/**< 标题 */
@property (nonatomic, strong) UILabel * timeLabel;/**< 时间 */
@property (nonatomic, strong) UILabel * balanceLabel;/**< 余额 */
@property (nonatomic, strong) UILabel * countLabel;/**< 金额 */
@property (nonatomic, strong) UIView * line;/**< 线 */
- (void)initializeAppearance;/**< 一般界面初始化 */
@end

@implementation WPWalletDetailTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initializeAppearance];
    }
    return self;
}
#pragma mark - init
- (void)initializeAppearance {
    [self addSubview:self.titleLabel];
    [self addSubview:self.timeLabel];
    [self addSubview:self.balanceLabel];
    [self addSubview:self.countLabel];
    [self addSubview:self.line];
}
#pragma mark - private method
- (NSString *)dateWithTimeInval:(NSNumber *)timeInval {
    NSDate * date = [NSDate dateWithTimeIntervalSince1970:[timeInval doubleValue]/1000];
    NSDateFormatter * formatter = [[NSDateFormatter alloc]init];
    formatter.dateFormat = @"yyyy-MM-dd";
    return [formatter stringFromDate:date];
}
#pragma mark - setter
- (void)setModel:(WPWalletDetailModel *)model {
    _model = model;
    _titleLabel.text = model.typeJson;
    _timeLabel.text = [self dateWithTimeInval:model.createDate];
    _balanceLabel.text = [NSString stringWithFormat:@"余额 %@", model.balance];
    _countLabel.text = [NSString stringWithFormat:@"%@", model.debit];
//    _balanceLabel.text = model.balance;
//    _countLabel.text = model.count;
}

#pragma mark - getter
- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = ({
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(10*DHFlexibleHorizontalMutiplier(), 0, 200, 30*DHFlexibleHorizontalMutiplier())];
            lab.textColor = COLOR_RGB(61, 61, 61, 1);
            lab.font = [UIFont systemFontOfSize:16*DHFlexibleHorizontalMutiplier()];
            
            lab;
        });
    }
    return _titleLabel;
}
- (UILabel *)timeLabel {
    if (!_timeLabel) {
        _timeLabel = ({
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(200*DHFlexibleHorizontalMutiplier(), 0, 100*DHFlexibleHorizontalMutiplier(), 30*DHFlexibleHorizontalMutiplier())];
            lab.textColor = COLOR_RGB(61, 61, 61, 1);
            lab.font = [UIFont systemFontOfSize:14*DHFlexibleHorizontalMutiplier()];
            lab.textAlignment = NSTextAlignmentRight;
            lab;
        });
    }
    return _timeLabel;
}
- (UILabel *)balanceLabel {
    if (!_balanceLabel) {
        _balanceLabel= ({
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(10*DHFlexibleHorizontalMutiplier(), CGRectGetMaxY(self.titleLabel.frame) - 3*DHFlexibleHorizontalMutiplier(), 200, 30*DHFlexibleHorizontalMutiplier())];
            lab.textColor = COLOR_RGB(153, 153, 153, 1);
            lab.font = [UIFont systemFontOfSize:14*DHFlexibleHorizontalMutiplier()];
            lab;
        });
    }
    return _balanceLabel;
}
- (UILabel *)countLabel {
    if (!_countLabel) {
        _countLabel = ({
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(200*DHFlexibleHorizontalMutiplier(), CGRectGetMinY(self.balanceLabel.frame), 100*DHFlexibleHorizontalMutiplier(), 30*DHFlexibleHorizontalMutiplier())];
            lab.textColor = COLOR_RGB(115, 195, 6, 1);
            lab.font = [UIFont systemFontOfSize:14*DHFlexibleHorizontalMutiplier()];
            lab.textAlignment = NSTextAlignmentRight;
            lab;
        });
    }
    return _countLabel;
}
- (UIView *)line {
    if (!_line) {
        _line = ({
            UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, 60*DHFlexibleHorizontalMutiplier()-0.5, SCREEN_SIZE.width, 0.5)];
            view.backgroundColor = COLOR_RGB(211, 211, 211, 1);
            view;
        });
    }
    return _line;
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
